<?php
class Module_Models_WorkSend extends Zend_Db_Table_Abstract {
    protected $_name = "worksend";
    protected $_primary = "WorkID";
    protected $_primary_name;
    public function __construct()
    {
        parent::__construct();
        $this->_primary_name = $this->_primary;
    }
	public function getAllProcess($iSendID){
        $where = $this->getAdapter()->quoteInto("DocID = ?",$iSendID);
		$orders =' WorkDate DESC';
        // Lay du lieu
		$query = $this->select()->from($this)->where($where)->order($orders);
		//echo $query;exit;
        $rows = $this->getAdapter()->fetchAll($query);
		$count = sizeof($rows);
		$objDate = new Clound_Datetime();
		$fileObj = new Clound_File(null,false);
		$oCacheFile = new Clound_CacheFile();
		$arrWorkType = $oCacheFile->getList('DM15');
		$oCloundPublic = new Clound_Public();			
		for($i=0;$i<$count;$i++)
		{
			$date = (string)$rows[$i]['WorkDate'];
			if($date){
				$objDate->set($date,'yyyy-MM-dd HH:mm:ss');
				$rows[$i]['WorkDate'] = $objDate->toString('dd/MM/yyyy HH:mm:ss');			
			}
			$rows[$i]['WorkType'] = $oCloundPublic->getNameByCode($arrWorkType, $rows[$i]['WorkType']);
			$rows[$i]['Result'] = $fileObj->SumContenAndFile('Result','WorkID','worksend','WORK',$rows[$i]);
		}
        return $rows;		
	}
    public function deleteNotIn($iSendID,$aListID){
        $where = $this->getAdapter()->quoteInto("DocID = ?",$iSendID)
				.$this->getAdapter()->quoteInto(" AND Status = ?",'CHO_XU_LY')
				.$this->getAdapter()->quoteInto(" AND Role = ?",'Y_KIEN_DU_THAO')
				.$this->getAdapter()->quoteInto(" AND $this->_primary_name NOT IN (?)", $aListID);
        return $this->delete($where);
    }
}
